import Block from "./Block.js";
import Direction from "./Direction.js";
import Config from "./Config.js";

export default class Rocket extends Block {
    constructor(x = 0, y = 0, width = 20, height = 20, imgSrc = Config.ImageAssets.RocketImgs.normal) {
        super(x, y, width, height, imgSrc);
        this.direction = Direction.TOP;
        this.speed = 400;
        this.damage = 0;
        this.status = 'on';
    }
    move() {
        if (this.status == 'on') {
            let step = this.speed / 1000 * Config.GameUpdateTick;
            switch (this.direction) {
                case Direction.TOP:
                    this.y -= step;
                    break;
                case Direction.RIGHT:
                    this.x += step;
                    break;
                case Direction.BOTTOM:
                    this.y += step;
                    break;
                case Direction.LEFT:
                    this.x -= step;
                    break;
            }
        }
    }
    explode() {
        this.width = 40;
        this.height = 40;
        this.x -= 10;
        this.y -= 10;
        this.status = 'explode';
        this.img.src = Config.ImageAssets.RocketImgs.boom;
        setTimeout((() => {
            this.status = 'die';

        }).bind(this), 100);
    }
}